package ClientCommTests;

import static org.junit.Assert.*;

import org.junit.Test;

import client.TelnetClient;
import clientCommunicationHandler.ClientServerMsgHandler;

public class ClientServerMsgHandlerTest {

	@Test
	public void parseServerMsgLoginSuccessChangeUserNametest() {
		ClientServerMsgHandler tMsgHandler = new ClientServerMsgHandler();
		TelnetClient.tempUserName = "tamir";
		tMsgHandler.parseServerMsg("login\nsuccess\n");
		assertTrue(TelnetClient.userName == "tamir");
		System.out.println("the user name is "+TelnetClient.userName);
		assertEquals("tamir", TelnetClient.userName);
	}

	@Test
	public void parseServerMsgLoginSuccessChangeMenu() {
		ClientServerMsgHandler tMsgHandler = new ClientServerMsgHandler();
		TelnetClient.tempUserName = "tamir";
		tMsgHandler.parseServerMsg("login\nsuccess\n");
		
		
		System.out.println(TelnetClient.menu);
		System.out.println("[user: tamir] please make your choice:\n\t1. Logout\n\t2. view_Forums\n\t3. Exit");
		System.out.println("endLine");
//		assertTrue(TelnetClient.menu.equals("[user: tamir] please make your choice:\n\t1. Logout\n\t2. view_Forums\n\t3. Exit"));
		
	}
	
	@Test
	public void getRestOfMenuTest(){
		System.out.println("enter rest of menu");
		ClientServerMsgHandler tClient = new ClientServerMsgHandler();
		tClient.getRestOfTheMenu(2);//3 for user that is not log in
		System.out.println(TelnetClient.menu);
		assertEquals(TelnetClient.menu, "[user: tamir] please make your choice:\n\t1. Logout\n\t2. view_Forums\n\t3. Exit\n");
	}
	
	@Test 
	public void parseServerMsgThreadList(){
		ClientServerMsgHandler tMsgHandler = new ClientServerMsgHandler();
		String demoServerMsg = "threadList\n3:temp1\n";
		StringBuilder newMenu = tMsgHandler.buildNewViewMenu(demoServerMsg, "threadList");
		System.out.println(newMenu);
		assertEquals(newMenu,"\n\t1. threadList 3:temp1\n\t2. add\n\t3. back\n");
		
	}
	
	@Test
	public void parseServerMsgPostList(){
		
		ClientServerMsgHandler tMsgHandler = new ClientServerMsgHandler();
		String demoServerMsg = "threadList\n3:temp1\n";
		StringBuilder newMenu = tMsgHandler.buildNewViewMenu(demoServerMsg, "threadList");
		System.out.println(newMenu);
		assertEquals(newMenu,"\n\t1. threadList 3:temp1\n\t2. add\n\t3. back\n");
		
		
	}
	
	

}
